package com.qfedu.service.impl;

import com.qfedu.mapper.StageMapper;
import com.qfedu.mapper.ProjectMapper;
import com.qfedu.model.Stage;
import com.qfedu.model.Project;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.StageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author LiJH
 * @date 2023-02-10
 */
@Service
public class StageServiceImpl implements StageService {
    @Autowired
    private StageMapper stageMapper;
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {

        PageResult pageResult = new PageResult();
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        long count = stageMapper.count();
        pageResult.setTotal(count);
        List<Stage> page = stageMapper.findPage((currentPage - 1) * pageSize, pageSize);
        pageResult.setRows(page);
        return pageResult;
    }

    @Override
    public int addStage(Stage stage) {
        stage.setUpdatetime(new Date());
        return stageMapper.addStage(stage);
    }

    @Override
    public Stage findById(String sid) {
        return   stageMapper.findById(sid);
    }

    @Override
    public int editStage(Stage stage) {
        stage.setUpdatetime(new Date());
        int i = stageMapper.editStage(stage);
        return i;
    }

    @Override
    public int deleteBySid(String sid) {
        return stageMapper.deleteBySid(sid);
    }

    @Override
    public List<Stage> findByPid(int pid) {
        List<Stage> byPid = stageMapper.findByPid(pid);
        return byPid;
    }
}